﻿using Miao;
using Sirenix.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class ModContentTexture : ModContentHolder<Texture2D>
{

    //public static Texture2D Get(string itemPath)
    //{
    //    if (ContentDict.TryGetValue(itemPath, out var texture))
    //    {
    //        return texture;
    //    }
    //    return Resources.Load<Texture2D>(MiaoFilePaths.ContentPath<AudioClip>() + itemPath);
    //}

    public override string Folder =>   "Textures\\";


    public ModContentTexture(ModContentPack mod) : base(mod)
    {
       
    }

    public override void AddFile(FileInfo file)
    {
        Texture2D texture2D = new Texture2D(2, 2);

        if (file.Extension == ".png" || file.Extension == ".jpg")
        {
            using (FileStream fileStream = file.OpenRead())
            {
                byte[] buffer = new byte[fileStream.Length];
                fileStream.Read(buffer, 0, buffer.Length);

                texture2D.LoadImage(buffer);
                texture2D.name = Path.GetFileNameWithoutExtension(file.Name);
            }
            string path = GetSubPath(file);
            ContentDict.Add(path, texture2D);//添加到泛型组内

        }
    }

}

